package com.cskaoyan.service;

import com.cskaoyan.mapper.AccountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author stone
 * @date 2022/10/10 15:52
 */
@Service
public class AccountServiceImpl implements AccountService{

    // service层使用的是mapper组件
    @Autowired
    AccountMapper accountMapper;

    @Override
    public void transfer(Integer fromId, Integer destId, Integer money) {
        Integer fromMoney = accountMapper.selectMoneyById(fromId) - money;
        Integer destMoney = accountMapper.selectMoneyById(destId) + money;

        /*fromMoney -= money;
        destMoney += money;*/

        int update1 = accountMapper.update(fromId, fromMoney);
        int update2 = accountMapper.update(destId, destMoney);
    }
}
